PATHMac OS 8 and 9 Developer Documentation > Interapplication Communication > AppleScript for Scripters >

AppleScript Language Guide

   

Interrupting a Script Application's Handlers

A stay-open script application handles incoming commands even if it is already running a handler in response to a previous command. This means that execution of a handler can be interrupted while another handler is run. Because script applications are not multithreaded, execution of the first handler pauses until the second one finishes. This is known as "last-in, first-out" event handling.

This can cause problems if both handlers modify the same script property or global variable or if both attempt to modify an application's data. For example, suppose that running a script application named increment causes it to increment the property p for several minutes:

property p : 0

on close
    set temp to p
    set p to 0
    return temp
end close

set p to 0
repeat 1000000 times
    set p to p + 1
end repeat

If this script application receives a Close command while it is running:

tell application "Increment" to close

AppleScript can't deal with such interruptions automatically.


© 1999 Apple Computer, Inc. – (Last Updated 21 May 99)